Ext.define('component.marketing.pinChange', {
	extend : 'Ext.form.Panel',
	initComponent:function(){
		var queryProjectBusiness = new Ext.data.Store({
			        singleton:true,
			        autoDestroy:true,
			        fields: ["id", "projectName"],
			        proxy:{
			            type:'ajax',
			            url:contextPath+'/estate/project/findProjectList?resourcesCode=menu_0003_0001',
			            reader:{
		                   type: 'json', 
		                   root: 'root'  //数据
		              }
			        } ,
			        autoLoad: false
		});
		queryProjectBusiness.load({
			callback:function(records, options, success){
				var count = queryProjectBusiness.getCount();
				if(count>0){
					var id = queryProjectBusiness.getAt(0).get("id");
					Ext.getCmp('bcProjectStore').setValue(id)
				}
				if(Ext.Array.contains(idata,"marketing:list:all")){
					var data = {"projectName": "全部", "id": '-1'};
					var rs = Ext.create(data);
					queryProjectBusiness.insert(count+1, rs);
				}
			}
		});
		
		
		var queryForm = Ext.create("Ext.form.Panel", {
			minHeight:170,
		    title: "查询条件",
		    collapsible: true,  //可折叠
		    autoScroll: false,   //自动创建滚动条
		    defaultType: 'textfield',
		    defaults: {
		    	 anchor: '100%'
		    },
		    fieldDefaults: {
		        margin: 2,
		        labelWidth: 80,
		        labelAlign: "right",
	            margin: "5 0 0 0"
		    },
		    items: [
	            {
				    xtype: "container",
				    layout: "hbox",
				    items: [{
					    xtype: "container",
					    layout: "hbox",
					    items: [{  
					    		id:'bcProjectStore',
					    		store:queryProjectBusiness,
					            xtype:'combobox',
					            name: "projectId",
					            valueField: "id",  
					            displayField: "projectName",
					            fieldLabel:'所属项目',
					            queryMode:'local',
					            typeAhead: true,
					            editable: false
					        },{
					        	xtype: "textfield",
					        	name:"customerName",
					        	fieldLabel: "客户名称"
					        }
			        	]
					}]
				},{
		            xtype: "container",
		            layout: "hbox",
		            items: [{
				        	xtype: "textfield",
				        	name:"mobile",
				        	fieldLabel: "客户电话",
				        	name:"customerPhone"
				        },{
				        	xtype: "textfield",
				        	fieldLabel: "经纪人",
				        	name:"userName"
				        }
		            ]
		        },{
					xtype: "container",
					layout: "hbox",
					items: [
						{
							xtype: "textfield",
							name:"combinedName",
							fieldLabel: "房号"
						},
						{ xtype: "datefield", name: "checkDateBefore",fieldLabel: "退房日期",format:'Y-m-d'},
		                {margin: "0 5 0 5",xtype: 'displayfield',value:'-'},
		                { xtype: "datefield", name: "checkDateAfter", format:'Y-m-d'}
					]
				}
	        ],
		    buttons: [{ xtype: "button", text: "查询",handler:function(){
	        	var pagingTool=Ext.getCmp("businessChangeInfo");
	        	pagingTool.moveFirst();
		    }  
				  	  
		    },{xtype: "button", text: "清空",handler:function(){
		    	queryForm.getForm().reset();
		    }
		    },{xtype:"button",text:"导出",hidden:businessChangeExport,handler:function(){
		    	var count = gridbusinessChangePanel.getStore().getCount();
		    	if(count<=0){
		    		Ext.MessageBox.alert("系统提示","没有可导出的数据");
		    	}else{
		    		var value = encodeURI(encodeURI(JSON.stringify(gridBusinessChange.proxy.extraParams),"utf-8"));
		        	location.href=jypath+'/marketing/businessChange/businessChangeExport?value='+value;
		    	}
	        	
			}
			}]
		    });
		var gridBusinessChange = Ext.create('Ext.data.Store', {
	        fields: ["id","customerPhone","businessStatus","businessSecStatus", "auditStatus"
	                 , "checkDate" , "customerName","roomId","combinedName"
	                 ,"houseTypeName","calculateArea","subscribeAmount","userName","received"
	                 ,"retired"],
	        pageSize: 10,  
	        remoteSort: false,
	        proxy: {
	            type: 'ajax',
	            url: jypath+'/marketing/businessChange/getModelByPage',
	            actionMethods: { read: 'POST' },
	            reader: {   
	                type: 'json', 
	                root: 'rows',  
	                totalProperty: 'total' 
	            }
	        },
	        autoLoad: true  //即时加载数据
	    });
		
		
		gridBusinessChange.on("beforeload",function(){
	        Ext.apply(gridBusinessChange.proxy.extraParams,queryForm.getForm().getValues());
	        var projectId = Ext.getCmp("bcProjectStore").getValue();
	        if(projectId == "-1"){
	        	gridBusinessChange.proxy.extraParams.projectId = "";
	        }
	        gridBusinessChange.proxy.extraParams.resourcesCode = resourcesCode;
	       });
		
		
		var gridbusinessChangePanel = Ext.create('Ext.grid.Panel', {
			minHeight:600,
			store:gridBusinessChange,
	        columnLines: true,
	        columns: [{
	            text: '退房日期',
	            dataIndex: 'checkDate',
	            renderer:function(value){
	            	if(value!=null&&value!=""){
		            	return Ext.Date.format(new Date(value),'Y-m-d')
	            	}else{
	            		return "";
	            	}
	            }
	        },{
	            text     : '客户名称', 
	            dataIndex: 'customerName'
	        },{
	            text     : '客户手机',
	            dataIndex: 'customerPhone',
	            width:250
	        },{
	            text     : '房号',
	            dataIndex: 'combinedName',
	            width:250
	        },{
	            text     : '户型',
	            dataIndex: 'houseTypeName'
	        },{
	            text     : '计价面积(平方米)',
	            dataIndex: 'calculateArea'
	        },{
	            text     : '合同金额(元)',
	            dataIndex: 'subscribeAmount', renderer: Ext.util.Format.numberRenderer('0,000.00')
	        },{
	            text     : '已收金额',
	            dataIndex: 'received'
	        },{
	            text     : '退款金额',
	            dataIndex: 'retired'
	        },{
	            text     : '经纪人',
	            dataIndex: 'userName'
	        },{
	            text     : '业务状态',
	            dataIndex: 'businessStatus'
	        },{
	            text     : '审核状态',
	            dataIndex: 'auditStatus'
	        }],
	        title: '退换列表',
	        dockedItems: [{  
	            xtype: 'pagingtoolbar',  
	            store:gridBusinessChange,
	            dock: 'bottom',  
	            displayInfo: true,  
	            emptyMsg:"没有数据",  
	            displayMsg:"显示从{0}条数据到{1}条数据，共{2}条数据",
	            id:'businessChangeInfo'
	        }
	        ]
	    });
		
		
		
		var defaultConfigg = {
				defaults: {  
		            split: true,    //有分割线  
		            collapsible: true  //可以折叠
		        },
				items:[queryForm,gridbusinessChangePanel]
		};
		Ext.apply(this,defaultConfigg);
		this.callParent(arguments);
	}
});